package org.open.cobertura.core.data;

import org.open.cobertura.core.model.CoberturaData;

import javax.swing.text.html.parser.Entity;
import java.util.Arrays;
import java.util.Map;

/**
 * 运行时数据元素实现
 */
public class CoberturaRuntimeData implements ICoberturaRuntimeData {


    @Override
    public byte[] accept(ICoberturaRuntimeDataVisitor visitor) {
        return visitor.visit(this);
    }

    /**
     * 收集运行时数据
     */
    public byte[] collect(){
       Map<Long, CoberturaData> coberturaDataMap=CoberturaRuntimeStore.getInstance().getRuntimeData().getCoberturaData();
       StringBuilder data=new StringBuilder();
       for(Map.Entry<Long,CoberturaData> entry:coberturaDataMap.entrySet()) {
           data.append(entry.getValue().getId()).append(",");
           data.append(entry.getValue().getName()).append(",");
           data.append(Arrays.toString(entry.getValue().getProbes())).append("\r\n");
       }
       return data.toString().getBytes();
    }
}
